package com.lzw.breezeNovel.webApp.service.impl.novel;

import com.lzw.breezeNovel.common.exception.BaseException;
import com.lzw.breezeNovel.model.entity.pojo.novel.Author;
import com.lzw.breezeNovel.webApp.mapper.novel.AuthorMapper;
import com.lzw.breezeNovel.webApp.service.novel.AuthorService;
import com.lzw.breezeNovel.webApp.vo.novel.AuthorVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.service.novel.impl
 * @date 2025/3/3
 * @description 作者表
 */
@Service
@SuppressWarnings("all")
public class AuthorServiceImpl implements AuthorService {

    /**
     * 注入作者表的mapper
     */
    @Autowired
    private AuthorMapper authorMapper;


    /**
     * 根据作者姓名获取作者信息
     * @param authorName
     * @return
     */
    @Override
    @Transactional(readOnly = true)
    public AuthorVo getAuthorByBookId(String authorName) {
        //根据作者名查询作者信息
        Author author = authorMapper.selectByAuthorName(authorName);
        //判断是存在
        if (author == null) {
            throw new BaseException(500,"作者不存在");
        }
        //创建作者信息vo
        AuthorVo authorVo = new AuthorVo();
        //将作者信息赋值给作者信息vo
        BeanUtils.copyProperties(author,authorVo);
        return authorVo;
    }
}
